#include<iostream>
#include<algorithm>
using namespace std;
const int N = 5010;
typedef pair<int, int> PII;
#define x first
#define y second
PII q[N];
int f[N];
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> q[i].x >> q[i].y;
	}
	sort(q, q + n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		f[i] = 1;
		for (int j = 0; j < i; j++) {
			if (q[i].y > q[j].y) {
				f[i] = max(f[i], f[j] + 1);
			}
		}
		ans = max(ans, f[i]);
	}
	cout << ans << endl;
	return 0;
}